package com.nbsaas.boot.wms.api.domain.controller;

import com.nbsaas.boot.wms.api.domain.request.ProductAllocationQueryRequest;
import com.nbsaas.boot.wms.api.domain.response.ProductAllocationResponse;
import com.nbsaas.boot.wms.api.domain.response.ShopAllocationSummaryResponse;
import com.nbsaas.boot.wms.api.domain.service.ProductAllocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品配货查询控制器
 */
@RestController
@RequestMapping("/api/wms/product-allocation")
public class ProductAllocationController {

    @Autowired
    private ProductAllocationService productAllocationService;

    /**
     * 查询商品在指定店铺的配货情况
     * @param request 查询请求
     * @return 配货情况列表
     */
    @PostMapping("/query")
    public List<ProductAllocationResponse> queryProductAllocation(@RequestBody ProductAllocationQueryRequest request) {
        return productAllocationService.queryProductAllocation(request);
    }

    /**
     * 查询商品在多个店铺的配货汇总情况
     * 如果某个店铺没有配货，返回配货数量为0的记录
     * @param productId 商品ID
     * @param shopIds 店铺ID列表
     * @return 店铺配货汇总列表
     */
    @GetMapping("/summary")
    public List<ShopAllocationSummaryResponse> getProductAllocationSummary(
            @RequestParam("productId") Long productId,
            @RequestParam("shopIds") List<Long> shopIds) {
        return productAllocationService.getProductAllocationSummaryByShops(productId, shopIds);
    }

    /**
     * 查询商品在指定店铺的配货数量
     * 如果该店铺没有配货，返回0
     * @param productId 商品ID
     * @param shopId 店铺ID
     * @return 配货数量
     */
    @GetMapping("/quantity")
    public Integer getProductAllocationQuantity(
            @RequestParam("productId") Long productId,
            @RequestParam("shopId") Long shopId) {
        return productAllocationService.getProductAllocationQuantityByShop(productId, shopId);
    }

    /**
     * 查询商品在指定店铺的可用配货数量
     * @param productId 商品ID
     * @param shopId 店铺ID
     * @return 可用配货数量
     */
    @GetMapping("/available-quantity")
    public Integer getAvailableAllocationQuantity(
            @RequestParam("productId") Long productId,
            @RequestParam("shopId") Long shopId) {
        return productAllocationService.getAvailableAllocationQuantityByShop(productId, shopId);
    }

    /**
     * 查询商品在指定店铺的配货状态
     * @param productId 商品ID
     * @param shopId 店铺ID
     * @return 配货状态
     */
    @GetMapping("/status")
    public String getProductAllocationStatus(
            @RequestParam("productId") Long productId,
            @RequestParam("shopId") Long shopId) {
        return productAllocationService.getProductAllocationStatusByShop(productId, shopId);
    }
} 